/*
 * @(#)GSProductInfoDownServlet.java   
 *
 * Project: CUPSecureBM
 * 
 * Modify Information:
 *  Author          Date                Description
 * ==============   =================   =====================
 *  yonggangguo     2005-12-29             Create this file
 *  Tuthmos Liu     2008-06-16           增加图件号
 * Copyright notice:
 *   Copyright (c) 2001-2005 Beijing HiTRUST Technology Co., Ltd.
 *   1808 Room, Science & Technology Building, No. 9 South Street,
 *   Zhong Guan Cun, Haidian District, Beijing ,100081, China
 *   All rights reserved.
 *
 *   This software is the confidential and proprietary information of
 *   HiTRUST.COM, Inc. ('Confidential Information').  You shall not
 *   disclose such Confidential Information and shall use it only in
 *   accordance with the terms of the license agreement you entered
 *   into with HiTRUST.
 */

package com.hitrust.gs.action;

import java.io.File;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hitrust.gs.bean.GSManufactureBean;
import com.hitrust.gs.dao.GSManufactureDAO;
import com.hitrust.gs.lib.GSSystemConfigurator;

public class GSProductPictureInsertServlet extends HttpServlet {

    public void init(ServletConfig aConfig) throws ServletException {
        super.init(aConfig);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
			String path=GSSystemConfigurator.getParam("gs.pic.filePath");	
		try {
			System.out.println("开始执行.....");
				File file = new File(path);
				System.out.println("文件路径"+path);
				String[] files=file.list();
				GSManufactureDAO manuDao=new GSManufactureDAO();
				for(int i=0;i<files.length;i++){
					System.out.println("文件夹"+files[i]);
					boolean flag=manuDao.getProductPictureByConcentricityCode(files[i]);
					GSManufactureBean bean=manuDao.getManufactureByConcentricityCode(files[i]);
					if(!flag&&bean!=null){
						String savePath = path + files[i] + "/";// 图片路径
						File picFile = new File(savePath);
						String[] picfiles=picFile.list();
						if(picfiles.length==0){
							System.out.println("文件夹"+files[i]+"不存在图片");
						}else{
							System.out.println("文件夹"+files[i]+"存在图片");
							manuDao.insertProductPicture(files[i]);
						}
					}
					if(bean==null){
						System.out.println("文件夹"+files[i]+"不符合要求");
					}
				}
				System.out.println("执行成功.....");
				response.getWriter().print("{'success':true,'message':'执行成功'}");
		} catch (Exception e) {
				try {
					System.out.println("执行失败.....");
					response.getWriter().print("{'success':false,'message':'执行失败'}");
				} catch (IOException e1) {
					e1.printStackTrace();
				}
		}
	}

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
        doPost(request, response);
    }
}
